<template>
  <view class="flex-col page">
    <view class="flex-col group_1" >
		<scroll-view scroll-y="true" v-if="list.length>0" :style="{height:scrollHeight+'px'}" @scrolltolower="loadmore">
      <view class="flex-col list">
        <view class="flex-col list-item" :key="i" v-for="(item, i) in list">
          <view class="justify-between">
            <text class="text_1">{{item.message}}</text>
            <text class="text_3">{{item.createDate}}</text>
          </view>
          <text class="text_5">巡检工序：{{item.processName}}</text>
          <text class="text_7">巡检子项目：{{item.childProcessName}}</text>
          <text class="text_9">巡检时间：{{item.inspectionDate}}</text>
          <view class="justify-end group_3">
            <text class="text_11">去查看</text>
            <text class="text_13">I</text>
            <text class="text_15" @click="del(item.id,i)">删除</text>
          </view>
        </view>
      </view>
	  </scroll-view>
	  <view class="" v-else>
	  	<u-empty style="height: 100vh;" width="250" mode="data" textSize="30rpx"
	  		icon="http://cdn.uviewui.com/uview/empty/order.png">
	  	</u-empty>
	  </view>
      <view class="flex-col items-end section_4">
        <view class="flex-col items-center text-wrapper" @click="deleteAll"><text class="text_25">清空消息</text></view>
      </view>
    </view>
	
	<u-loadmore v-show="more" height="100" fontSize="26" :status="status" />
  </view>
</template>

<script>
  export default {
    components: {},
    data() {
      return {
        list: [],
		page:{
					  pageNum:1,
					  pageSize:10
		},
		more:false,
			status: 'loadmore',
		scrollHeight:0,
      };
    },
	created() {
	  this.queryInspectionMessage()	
	},
	mounted() {
	   	this.getScrollHeight();
	},
    methods: {
		getScrollHeight()
		{
			const query = uni.createSelectorQuery().in(this);
			query.select('.page').boundingClientRect();
			query.select('.section_4').boundingClientRect();
			query.exec(r=>{
				
					//进入页面滚动到底部
				 this.scrollHeight=r[0].height-r[1].height;
			
			});
			console.log(this.scrollHeight);
		},
		loadmore()
		{
			// this.status = "loading";
			this.more = true;
			this.page.pageNum++;
			this.queryInspectionMessage(1)
		},
		queryInspectionMessage(type=0)
		{
		  this.$http('message.queryInspectionMessage',this.page).then(r=>{
			 if(r.code==200 && r.data)
			 {
				 if(type==0)
				 {
					 this.list=r.data; 
				 }else{
					 if (r.data.length > 0) {
					 	this.list = this.list.concat(r.data);
					 	this.status = "loadmore";
					 } else {
					 	this.status = "nomore";
					 
					 }
				 }
				
			 }
		  });	
		},
		del(id,i)
		{
			
			uni.showModal({
					title: '提示',
					// 提示文字
					content: '确认删除该条信息吗？',
					// 取消按钮的文字自定义
					cancelText: "取消",
					// 确认按钮的文字自定义
					confirmText: "删除",
					//删除字体的颜色
					confirmColor:'red',
					//取消字体的颜色
					cancelColor:'#000000',
					success: res=> {
					if (res.confirm) {
						this.$http('message.deleteMessageById',{
							inspectionMessageId:id
						}).then(r=>{
						   if(r.code==200)
						   {
							   this.list.splice(i,1);
						   }
						});
					}else {
						// 执行取消后的操作
					}
				}
			
		
         })
			
		},
		deleteAll()
		{
			uni.showModal({
								title: '提示',
								// 提示文字
								content: '确认清空吗？',
								// 取消按钮的文字自定义
								cancelText: "取消",
								// 确认按钮的文字自定义
								confirmText: "删除",
								//删除字体的颜色
								confirmColor:'red',
								//取消字体的颜色
								cancelColor:'#000000',
								success: res=> {
								if (res.confirm) {
									this.$http('message.deleteAllInspectionMessage').then(r=>{
									   if(r.code==200)
									   {
										   this.list=[];
									   }
									});
								}else {
									// 执行取消后的操作
								}
							}
						
					
			})
		}
	},
  };
</script>

<style scoped lang="scss">
  .list-item {
    padding: 29rpx 22rpx 0 24rpx;
    background-color: #ffffff;
    border-radius: 16rpx;
  }
  .text_5 {
    margin-top: 30rpx;
    align-self: flex-start;
    color: #333333;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
  .text_7 {
    margin-top: 23rpx;
    align-self: flex-start;
    color: #333333;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
  .page{
	  height: 100vh;
  }
  .text_9 {
    margin-top: 29rpx;
    align-self: flex-start;
    color: #333333;
    font-size: 28rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 33rpx;
  }
  .group_3 {
    margin-top: 26rpx;
    padding: 22rpx 0 33rpx;
    border-top: solid 1rpx #eeeeee;
  }
  .text_1 {
    color: #333333;
    font-size: 32rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 38rpx;
  }
  .text_3 {
    margin-top: 12rpx;
    color: #999999;
    font-size: 24rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 28rpx;
  }
  .text_11 {
    margin-right: 40rpx;
    margin-bottom: 6rpx;
    color: #1d6aff;
    font-size: 24rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 28rpx;
  }
  .text_13 {
    margin-right: 39rpx;
    margin-top: 6rpx;
    color: #bfbfbf;
    font-size: 24rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 28rpx;
  }
  .text_15 {
    margin-bottom: 6rpx;
    color: #ff371d;
    font-size: 24rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 28rpx;
  }
  .page {
    background-color: #f6f7f9ff;
    width: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
  }
  .group_1 {
    padding-top: 15rpx;
    flex: 1 1 auto;
    overflow-y: auto;
	padding-bottom: 120rpx;
  }
  .list {
    padding: 0 24rpx;
  }
  .section_4 {
    position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
    padding: 20rpx 0;
    background-color: #ffffff;
    box-shadow: 0px -2rpx 4rpx 0px #00000014;
  }
  .list-item:last-of-type {
    margin-top: 20rpx;
  }
  .text-wrapper {
    margin-right: 32rpx;
    padding: 9rpx 0 19rpx;
    background-color: #1d6aff14;
    border-radius: 28rpx;
    width: 148rpx;
  }
  .text_25 {
    color: #1d6aff;
    font-size: 24rpx;
    font-family: '.AppleSystemUIFont';
    line-height: 28rpx;
  }
</style>